/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var req;
function validate() {
    var idField = document.getElementById("email");
    var url = "register.do?action=validateEmail&email=" + escape(idField.value);
    if(window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    req.open("GET", url, true);
    req.onreadystatechange = callback;
    req.send(null);
}

function callback() {
    if(req.readyState == 4) {
        if(req.status == 200) {
                //alert(req.responseText);
            var msg = req.responseXML.getElementsByTagName("msg")[0];
                //alert(msg);
            setUserMsg(msg.childNodes[0].nodeValue);
        }
    }
}

function setUserMsg(msg) {
        //alert(msg);
    mdiv = document.getElementById("usermsg");
    //mdiv.innerHTML = "<font color='red'>username exists</font>";
    if(msg == "invalid") {
        mdiv.innerHTML = "<font color='red'>Username exists</font>";
    } else {
        mdiv.innerHTML = "<font color='green'>Congratulations! You can use this username!</font>";
    }
}

function comfirmPassword() {
    var pwd = document.getElementById("password");
    var pwd2 = document.getElementById("password2");
    mdiv = document.getElementById("comfirmpwd");

    if(escape(pwd.value) != escape(pwd2.value)) {
        mdiv.innerHTML = "<font color='red'>Comfirm Password Wrong!</font>";
    } else {
        mdiv.innerHTML = "<font color='green'>Password Right!</font>";
    }
}


